/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('aiearth-meteorology', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model DailyWeatherQueryRequest {
  element?: string(name='element', description='要素'),
  forecastTimestamp?: string(name='forecastTimestamp', description='预报时间'),
  latitude?: double(name='latitude', description='纬度'),
  location?: string(name='location', description='位置'),
  longitude?: double(name='longitude', description='经度'),
  product?: string(name='product', description='产品代号'),
}

model DailyWeatherQueryResponseBody = {
  code?: long(name='code', description='响应码'),
  message?: string(name='message', description='响应信息'),
  requestId?: string(name='requestId', description='Id of the request'),
  result?: [ 
    {
      data?: [ 
        {
          elements?: [ 
            {
              element?: string(name='element'),
              value?: string(name='value'),
            }
          ](name='elements'),
          forecastTimestamp?: string(name='forecastTimestamp'),
        }
      ](name='data'),
      location?: {
        latitude?: double(name='latitude', description='纬度'),
        longitude?: double(name='longitude', description='经度'),
      }(name='location', description='位置'),
    }
  ](name='result', description='响应结果'),
  success?: boolean(name='success', description='请求是否成功'),
}

model DailyWeatherQueryResponse = {
  headers: map[string]string(name='headers'),
  body: DailyWeatherQueryResponseBody(name='body'),
}

async function dailyWeatherQuery(request: DailyWeatherQueryRequest): DailyWeatherQueryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return dailyWeatherQueryWithOptions(request, headers, runtime);
}

async function dailyWeatherQueryWithOptions(request: DailyWeatherQueryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): DailyWeatherQueryResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.element)) {
    query['element'] = request.element;
  }
  if (!Util.isUnset(request.forecastTimestamp)) {
    query['forecastTimestamp'] = request.forecastTimestamp;
  }
  if (!Util.isUnset(request.latitude)) {
    query['latitude'] = request.latitude;
  }
  if (!Util.isUnset(request.location)) {
    query['location'] = request.location;
  }
  if (!Util.isUnset(request.longitude)) {
    query['longitude'] = request.longitude;
  }
  if (!Util.isUnset(request.product)) {
    query['product'] = request.product;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DailyWeatherQuery',
    version = '2022-03-22',
    protocol = 'HTTPS',
    pathname = `/weather/v2/daily`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model ForecastRasterQueryRequest {
  duration?: string(name='duration'),
  element?: string(name='element'),
}

model ForecastRasterQueryResponseBody = {
  code?: long(name='code', description='响应码'),
  message?: string(name='message', description='响应信息'),
  requestId?: string(name='requestId', description='Id of the request'),
  result?: {
    data?: [ 
      {
        index?: int32(name='index'),
        timestamp?: long(name='timestamp'),
        url?: string(name='url'),
      }
    ](name='data'),
    element?: string(name='element'),
    extent?: [ float ](name='extent'),
    format?: string(name='format'),
    reportTimestamp?: long(name='reportTimestamp'),
  }(name='result'),
  success?: boolean(name='success', description='请求是否成功'),
}

model ForecastRasterQueryResponse = {
  headers: map[string]string(name='headers'),
  body: ForecastRasterQueryResponseBody(name='body'),
}

async function forecastRasterQuery(request: ForecastRasterQueryRequest): ForecastRasterQueryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return forecastRasterQueryWithOptions(request, headers, runtime);
}

async function forecastRasterQueryWithOptions(request: ForecastRasterQueryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ForecastRasterQueryResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.duration)) {
    query['duration'] = request.duration;
  }
  if (!Util.isUnset(request.element)) {
    query['element'] = request.element;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ForecastRasterQuery',
    version = '2022-03-22',
    protocol = 'HTTPS',
    pathname = `/visual/forecast/raster`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GridWeatherQueryRequest {
  element?: string(name='element', description='要素'),
  forecastTimestamp?: string(name='forecastTimestamp', description='预报时间'),
  latitude?: double(name='latitude', description='纬度'),
  longitude?: double(name='longitude', description='经度'),
  observationTimestamp?: string(name='observationTimestamp', description='观测时间'),
  product?: string(name='product', description='产品代号'),
  reportTimestamp?: string(name='reportTimestamp', description='起报时间'),
}

model GridWeatherQueryResponseBody = {
  code?: long(name='code', description='响应码'),
  message?: string(name='message', description='响应信息'),
  requestId?: string(name='requestId', description='Id of the request'),
  result?: [ 
    {
      data?: [ 
        {
          elements?: [ 
            {
              element?: string(name='element'),
              value?: string(name='value'),
            }
          ](name='elements'),
          forecastTimestamp?: string(name='forecastTimestamp', description='预报时间'),
          observationTimestamp?: string(name='observationTimestamp', description='观测时间'),
        }
      ](name='data', description='该位置的查询结果'),
      location?: {
        latitude?: double(name='latitude', description='纬度'),
        longitude?: double(name='longitude', description='经度'),
      }(name='location', description='位置'),
      reportTimestamp?: string(name='reportTimestamp', description='起报时间'),
    }
  ](name='result', description='响应结果'),
  success?: boolean(name='success', description='请求是否成功'),
}

model GridWeatherQueryResponse = {
  headers: map[string]string(name='headers'),
  body: GridWeatherQueryResponseBody(name='body'),
}

async function gridWeatherQuery(request: GridWeatherQueryRequest): GridWeatherQueryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return gridWeatherQueryWithOptions(request, headers, runtime);
}

async function gridWeatherQueryWithOptions(request: GridWeatherQueryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GridWeatherQueryResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.element)) {
    query['element'] = request.element;
  }
  if (!Util.isUnset(request.forecastTimestamp)) {
    query['forecastTimestamp'] = request.forecastTimestamp;
  }
  if (!Util.isUnset(request.latitude)) {
    query['latitude'] = request.latitude;
  }
  if (!Util.isUnset(request.longitude)) {
    query['longitude'] = request.longitude;
  }
  if (!Util.isUnset(request.observationTimestamp)) {
    query['observationTimestamp'] = request.observationTimestamp;
  }
  if (!Util.isUnset(request.product)) {
    query['product'] = request.product;
  }
  if (!Util.isUnset(request.reportTimestamp)) {
    query['reportTimestamp'] = request.reportTimestamp;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GridWeatherQuery',
    version = '2022-03-22',
    protocol = 'HTTPS',
    pathname = `/weather/v2/grid`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

